package view.components
{
	import flash.display.GradientType;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.geom.Matrix;
	import flash.text.TextField;
	
	import global.Resource;
	
	import utils.TextTool;
	
	public class CountTimer extends Sprite
	 {
		
		private var timerEffect:MovieClip;
		private var countText:TextField;
		
		public function CountTimer()
		{
			initBg();
			initTimerEffect();
			initText();
		}
		
		private function initText():void
		{
			countText = TextTool.getTextField(20,18,13,0xFFFFFF,false,true,"center");
			countText.x = timerEffect.x + timerEffect.width - 8;
			countText.y = -2;
			addChild(countText);
		}
		
		private function initTimerEffect():void
		{
			timerEffect = Resource.getEffect("NumberTimer");
			timerEffect.x = 30;
			timerEffect.y = 8;
			addChild(timerEffect);
		}
		
		private function initBg():void
		{
			
			var fillType:String = GradientType.LINEAR;
		    var colors:Array = [0xFF9900, 0xFF6600];
			var alphas:Array = [1, 1];
			var ratios:Array = [0x00, 0xFF];
			var matr:Matrix = new Matrix();
			matr.createGradientBox(80, 16, Math.PI / 2, 0, 0);
			
			with (graphics)
			{
				clear();
				beginGradientFill(fillType,colors,alphas,ratios,matr);
				drawRoundRect(0,0,80,16,15,15);
				endFill();
			}
		}
		
		public function update(count:String):void
		{
			countText.text = count;
		}
	}
}